package com.example.test1;

import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ErrorDialog extends DialogFragment  {
	
	// Use this instance of the interface to deliver action events
    public interface ErrorDialogListener {
	    public List<String> getErrors();
	}
	
	ErrorDialogListener mListener;
    
	@Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        // Instantiate the NoticeDialogListener so we can send events to the host
        mListener = (ErrorDialogListener) activity;
    }
	
	@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the Builder class for convenient dialog construction
		Activity activity = getActivity();
        
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setPositiveButton(R.string.ok, null);
        
        LinearLayout ll = new LinearLayout(activity);
        ll.setOrientation(LinearLayout.VERTICAL);
        
        List<String> errors = mListener.getErrors();
        for (String eitem : errors) {
        	TextView item = new TextView(activity);
        	item.setText(eitem);
        	item.setTextColor(Color.parseColor("#FFFFFF"));
        	item.setGravity(Gravity.LEFT);
        	ll.addView(item);
            
        }
        builder.setView(ll);
        // Create the AlertDialog object and return it
        return builder.create();
    }

}
